package com.sixth.controller.wx;

import com.fasterxml.jackson.databind.ser.Serializers;

import com.sixth.bean.bo.*;


import com.sixth.bean.bo.OrderIdBO;

import com.sixth.bean.bo.WXOrderCommentBO;


import com.sixth.bean.common.BasePageInfoVo;
import com.sixth.bean.common.BaseRespVo;
import com.sixth.bean.vo.WXOrderDetailVO;
import com.sixth.bean.vo.WXOrderGoodsVO;
import com.sixth.bean.vo.WXOrderSubmitVO;
import com.sixth.constant.Constant;
import com.sixth.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ljh
 * @version 1.0
 * @describition:
 * @since 2022/9/9 20:13
 **/

@RestController
@RequestMapping("wx/order")
public class WXOrderController {
    @Autowired
    OrderService orderService;

    @RequestMapping("list")
    public BaseRespVo list(WXOrderListBO wxOrderListBO){
        BasePageInfoVo pageInfoVo =  orderService.wxList(wxOrderListBO);

        return BaseRespVo.ok(pageInfoVo);
    }


    /**
     *
     * @author qys
     * @date 2022/9/11 1:13
     * @return BaseRespVo
     */
    @RequestMapping("comment")
    public BaseRespVo wxOrderComment(@RequestBody WXOrderCommentBO wxOrderCommentBO) {
        int code = orderService.wxOrderComment(wxOrderCommentBO);
        if (code == 614) {
            return BaseRespVo.invalidNoAndMsg("已不可评论", 614);
        }
        return BaseRespVo.ok();
    }

    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody OrderIdBO orderIdBO){


        int code = orderService.wxRefund(orderIdBO.getOrderId());
        if(code == Constant.NON){
            return BaseRespVo.invalidData();
        }

        return BaseRespVo.ok();
    }


    @RequestMapping("detail")
    public BaseRespVo detail(Integer orderId){

        WXOrderDetailVO wxOrderDetailVO = orderService.wxDetail(orderId);
        if(wxOrderDetailVO == null){
            return BaseRespVo.ok("查询失败");
        }

        return BaseRespVo.ok(wxOrderDetailVO);

    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody OrderIdBO orderIdBO){

        int code = orderService.wxDelete(orderIdBO.getOrderId());
        if(code == Constant.NON){
            return BaseRespVo.invalidData();
        }

        return BaseRespVo.ok();
    }

    @RequestMapping("confirm")
    public BaseRespVo confirm(@RequestBody OrderIdBO orderIdBO){

        int code = orderService.wxConfirm(orderIdBO.getOrderId());
        if(code == Constant.NON){
            return BaseRespVo.invalidData();
        }

        return BaseRespVo.ok();

    }


    @RequestMapping("cancel")
    public BaseRespVo cancel(@RequestBody OrderIdBO orderIdBO){

        int code = orderService.wxCancel(orderIdBO.getOrderId());
        if(code == Constant.NON){
            return BaseRespVo.invalidData();
        }

        return BaseRespVo.ok();
    }

    @RequestMapping("prepay")
    public BaseRespVo prepay(@RequestBody OrderIdBO orderIdBO){

        int code = orderService.wxPrepay(orderIdBO.getOrderId());
        if(code == Constant.EXPIRATED){
            return BaseRespVo.invalidData("订单已过期");
        }
        if(code == Constant.NON){
            return BaseRespVo.invalidData();
        }

        return BaseRespVo.ok();
    }

    @RequestMapping("submit")
    public BaseRespVo submit(@RequestBody WXOrderSubmitBo wxOrderSubmitBo){

        WXOrderSubmitVO wxOrderSubmitVO = orderService.wxSubmit(wxOrderSubmitBo);
        if(wxOrderSubmitVO == null){
            BaseRespVo.invalidData();
        }

        return BaseRespVo.ok(wxOrderSubmitVO);
    }

    @RequestMapping("goods")
    public BaseRespVo goods(WXOrderGoodsBO wxOrderGoodsBO){

        WXOrderGoodsVO wxOrderGoodsVO = orderService.wxGoods(wxOrderGoodsBO);

        if(wxOrderGoodsBO == null){
            return BaseRespVo.invalidData();
        }

        return BaseRespVo.ok(wxOrderGoodsVO);
    }

}
